﻿using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace LujWeb.Internal;

public class HandleContentResponder {

  public Task ResponseText(HttpResponse rsp, string content) {
    return Response(rsp, MediaTypeNames.Text.Plain, content);
  }

  public Task ResponseHtml(HttpResponse rsp, string content) {
    return Response(rsp, MediaTypeNames.Text.Html, content);
  }

  public async Task Response(HttpResponse rsp, string contentType, string content) {
    rsp.ContentType = contentType;
    rsp.ContentLength = Encoding.UTF8.GetByteCount(content);

    await rsp.WriteAsync(content);
  }
}
